import pkuseg
from wss.stopWords import stopwordslist

stopwordsText = r'stopwords\cn_stopwords.txt'
cut_all = False

def seg_depart_pkuseg(sentence:str, isDelStopWords:bool):
    stopwords = stopwordslist()
    seg = pkuseg.pkuseg()
    words = seg.cut(sentence)
    outWords = []
    for word in words:
        if isDelStopWords:
            if word not in stopwords:
                if word != '\t':
                    outWords.append(word)
        else:
            if word != '\t':
                outWords.append(word)
    return outWords

def seg_depart_Count_pkuseg(sentence:str, isDelStopWords:bool):
    seg = pkuseg.pkuseg()
    words = seg.cut(sentence)
    stopwords = stopwordslist()
    counts = {}
    for word in words:
        if  len(word) == 1:
            continue
        else:
            if isDelStopWords:
                if word not in stopwords:
                    counts[word] = counts.get(word, 0) + 1  
            else:
                counts[word] = counts.get(word, 0) + 1  
    items = list(counts.items())
    items.sort(key=lambda x: x[1], reverse=True)
    return items